/**
 * 
 */
package com.shareyi.joywindow.sys.utils;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Collections;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import org.codehaus.jackson.map.SerializerProvider;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
import org.codehaus.jackson.map.ser.StdSerializerProvider;

/**
 * @author ZhaoHongbo
 *
 */
public class JsonUtils {
	

	@SuppressWarnings("deprecation")
	public static String toJson(Object obj) {
		return JSON.toJSONString(obj);
	}
	
	@SuppressWarnings("rawtypes")
	public static <T> T readToT(String jsonText , Class<T> clazz) {
		return JSON.parseObject(jsonText,clazz);
	}
	
	/**
	 * 返回JSON数据构造成的Map
	 * 
	 * @param jsonText
	 * @return
	 */
	@SuppressWarnings("rawtypes")
	public static Map readToMap(String jsonText) {
		if(StringUtils.isEmpty(jsonText)){
			return Collections.EMPTY_MAP;
		}
		return JSON.parseObject(jsonText, HashedMap.class);
	}


}
